from enum import Enum
from typing import Optional
from uuid import uuid4
from attr import define, field
import attrs


class ColumnItemType(str, Enum):
    PRODUCT = "PRODUCT"
    COMPONENT = "COMPONENT"


@define
class CorrelationId:
    correlation_id: str = field(factory=lambda: uuid4().hex)


@define
class ColumnsInput:
    column_number: int = field(
        default=None, validator=[attrs.validators.ge(0), attrs.validators.lt(32767)]
    )
    external_product_id: Optional[str] = field(
        default=None,
        validator=[attrs.validators.min_len(1), attrs.validators.max_len(32)],
    )
    old_qty: Optional[int] = field(
        default=None,
        validator=[attrs.validators.ge(0), attrs.validators.lt(2147483647)],
    )
    new_qty: Optional[int] = field(
        default=None,
        validator=[attrs.validators.ge(0), attrs.validators.lt(2147483647)],
    )
    old_price: Optional[float] = field(
        default=None,
        validator=[attrs.validators.ge(0), attrs.validators.lt(99999999.99)],
    )
    new_price: Optional[float] = field(
        default=None,
        validator=[attrs.validators.ge(0), attrs.validators.lt(99999999.99)],
    )
    select_map: Optional[list[int]] = field(default=None)
    item_type: Optional[ColumnItemType] = field(factory=lambda: ColumnItemType.PRODUCT)


@define
class PlanogramInput(CorrelationId):
    machine_external_id: Optional[str] = field(
        default=None,
        validator=[attrs.validators.min_len(1), attrs.validators.max_len(32)],
    )
    columns: list[ColumnsInput] = field(factory=list)


@define
class PlanogramsBulkInputPayload:
    planograms: list[PlanogramInput] = field(factory=list)
