"""
██╗    ██╗ █████╗ ██████╗ ███╗   ██╗██╗███╗   ██╗ ██████╗
██║    ██║██╔══██╗██╔══██╗████╗  ██║██║████╗  ██║██╔════╝
██║ █╗ ██║███████║██████╔╝██╔██╗ ██║██║██╔██╗ ██║██║  ███╗
██║███╗██║██╔══██║██╔══██╗██║╚██╗██║██║██║╚██╗██║██║   ██║
╚███╔███╔╝██║  ██║██║  ██║██║ ╚████║██║██║ ╚████║╚██████╔╝
 ╚══╝╚══╝ ╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═══╝╚═╝╚═╝  ╚═══╝ ╚═════╝

         AUTO-GENERATED FILE - DO NOT EDIT!

This file was auto-generated by libretiny/generate_components.py.
Any manual changes WILL BE LOST on regeneration.

To customize this component:
  - Pin validators: Create gpio.py with validate_pin() or validate_usage()
  - Schema extensions: Create schema.py with COMPONENT_SCHEMA or COMPONENT_PIN_SCHEMA

Platform-specific code should be added to the main libretiny component
(__init__.py in esphome/components/libretiny/) rather than here.
"""

from esphome import pins
from esphome.components import libretiny
from esphome.components.libretiny.const import (
    COMPONENT_LN882X,
    KEY_COMPONENT_DATA,
    KEY_LIBRETINY,
    LibreTinyComponent,
)
from esphome.core import CORE

from .boards import LN882X_BOARD_PINS, LN882X_BOARDS

CODEOWNERS = ["@lamauny"]
AUTO_LOAD = ["libretiny"]
IS_TARGET_PLATFORM = True

COMPONENT_DATA = LibreTinyComponent(
    name=COMPONENT_LN882X,
    boards=LN882X_BOARDS,
    board_pins=LN882X_BOARD_PINS,
    pin_validation=None,
    usage_validation=None,
    supports_atomics=True,
)


def _set_core_data(config):
    CORE.data[KEY_LIBRETINY] = {}
    CORE.data[KEY_LIBRETINY][KEY_COMPONENT_DATA] = COMPONENT_DATA
    return config


# extend({}) makes this platform's own schema instance: BASE_SCHEMA is shared
# by every LibreTiny platform, and prepending this platform's _set_core_data
# onto the shared object would run it for every platform's validation once two
# platform modules are imported in one process (device-builder, tests).
CONFIG_SCHEMA = libretiny.BASE_SCHEMA.extend({})

PIN_SCHEMA = libretiny.gpio.BASE_PIN_SCHEMA

CONFIG_SCHEMA.prepend_extra(_set_core_data)


async def to_code(config):
    return await libretiny.component_to_code(config)


@pins.PIN_SCHEMA_REGISTRY.register("ln882x", PIN_SCHEMA)
async def pin_to_code(config):
    return await libretiny.gpio.component_pin_to_code(config)


# Called by writer.py; delegates to the shared libretiny implementation.
def copy_files() -> None:
    libretiny.copy_files()
