# Copyright (c) 2026 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from ...common.transformers.transformers import PretrainedConfig

DEFAULT_BLOCK_CONFIGS = [
    [[3, 96, 96, 1, True]],
    [[3, 96, 96, 1, False], [3, 96, 96, 1, False]],
    [
        [3, 96, 192, [2, 1], False],
        [3, 192, 192, 1, True],
        [3, 192, 192, 1, False],
        [3, 192, 192, 1, True],
        [3, 192, 192, 1, False],
        [3, 192, 192, 1, True],
        [3, 192, 192, 1, False],
    ],
    [
        [3, 192, 384, [2, 1], False],
        [3, 384, 384, 1, True],
        [3, 384, 384, 1, False],
    ],
]


class PPLCNetV4Config(PretrainedConfig):
    model_type = "pp_lcnet_v4"

    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.scale = kwargs.get("scale", 1.0)
        self.block_configs = kwargs.get("block_configs", DEFAULT_BLOCK_CONFIGS)
        self.stem_channels = kwargs.get("stem_channels", [3, 48, 96])
        self.reduction = kwargs.get("reduction", 4)
        self.hidden_act = kwargs.get("hidden_act", "relu")
        self.num_channels = kwargs.get("num_channels", 3)
        self.stem_strides = kwargs.get("stem_strides", [2, 1, 1, 2, 1])
        self.stem_type = kwargs.get("stem_type", "large")
        self.use_learnable_affine_block = kwargs.get(
            "use_learnable_affine_block", False
        )

        self.stage_out_channels = [blocks[-1][2] for blocks in self.block_configs]
