import { TBrand } from "./Brand";
import {
    defaultImageUrls,
    defaultUrl,
    TImage,
    TImageUrls,
    TImageWithField,
} from "./Image";
import { TPromotion } from "./Promotion";

export type TContentProduct = {
    type: "content";
    data: TContentData;
};

export type TContentData = {
    images: TImage[];
    description: string | null;
    specification: string | null;
    variants: TVariants[];
};

export interface TProduct {
    id: number;
    name: string;
    slug: string;
    product_category_1_id: number;
    product_category_2_id: number;
    product_category_3_id: number;
    product_category1?: TProductCategory;
    product_category2?: TProductCategory;
    product_category3?: TProductCategory;
    brand_id: number;
    brand?: TBrand;
    content: TContentProduct[];
    promotions?: TPromotion[];
    originalPrice: number;
    discountedPrice: number;
    maxDiscount: number;
    validUntil: string | null;
    isValid: boolean;
    created_at: string | null;
    updated_at: string | null;
}

export interface TVariants {
    active: boolean;
    attribute: string;
    price: number;
    available: boolean;
    weight: number;
    colors: TColors[];
}

export interface TColors {
    active: boolean;
    color: string;
    stock: number;
    length: number;
    width: number;
    height: number;
    depth: number;
}

export interface TProductCategoryProps {
    brands: TBrand[];
    children: TProductCategory[];
    product_category: TProductCategory;
}

export interface TPagination {
    total: number;
    current_page: number;
    last_page: number;
    per_page: number;
    first_page_url: string | null;
    next_page_url: string | null;
    prev_page_url: string | null;
    last_page_url: string | null;
}

export const defaultPagination = {
    total: 0,
    current_page: 1,
    last_page: 1,
    per_page: 10,
    first_page_url: null,
    next_page_url: null,
    prev_page_url: null,
    last_page_url: null,
};

export interface TProductOnProductCategory {
    data: TProduct[];
    pagination: TPagination;
}

export interface TImagesProductCategory {
    images: TImageWithField[];
}

export interface TContentProductCategory {
    type: string;
    data: TImagesProductCategory;
}

export interface TProductCategory {
    id: number;
    name: string;
    level: number;
    product_category_id: number | null;
    slug: string;
    content: TContentProductCategory[];
    created_at: string | null;
    updated_at: string;
    products?: TProductOnProductCategory;
    order?: number;
    product_category_children?: TProductCategory[];
}

export interface TProductAndPagination {
    data: TProduct[];
    pagination: TPagination;
}

export interface TProductCategoryCarousel {
    id: number;
    name: string;
    slug: string;
    urls: TImageUrls;
    alt_text: string | null;
    image_preview: string;
}

export interface TBannerData {
    banner_desktop: TImageWithField | null;
    banner_mobile: TImageWithField | null;
}

export const defaultProduct = {
    id: 0,
    name: "",
    slug: "",
    product_category_1_id: 0,
    product_category_2_id: 0,
    product_category_3_id: 0,
    brand_id: 0,
    content: [
        {
            type: "content" as const,
            data: {
                images: [
                    {
                        image: "",
                        urls: defaultImageUrls,
                        image_preview: "",
                        alt_text: "",
                    },
                ],
                description: "",
                specification: null,
                variants: [
                    {
                        active: true,
                        attribute: "Default",
                        price: 0,
                        available: true,
                        weight: 0,
                        colors: [
                            {
                                active: true,
                                color: "Default",
                                stock: 0,
                                length: 0,
                                width: 0,
                                height: 0,
                                depth: 0,
                            },
                        ],
                    },
                ],
            },
        },
    ],
    promotions: [],
    originalPrice: 0,
    discountedPrice: 0,
    maxDiscount: 0,
    validUntil: "",
    isValid: false,
    created_at: "",
    updated_at: "",
};

export interface TParams {
    pageParam: number;
    searchParam: string;
    pcl1Param: string;
    pcl2Param: string;
    pcl3Param: string;
    brandsParam: string[];
    promotionParam: string;
    minPriceParam: number | null;
    maxPriceParam: number | null;
}

export interface TFilters {
    page: number;
    search: string;
    pcl1: string;
    pcl2: string;
    pcl3: string;
    brands: string[];
    promotion: string;
    minPrice: number | null;
    maxPrice: number | null;
}

export interface TResponse {
    meta: {
        code: number;
        status: string;
        message: string | null;
    };
    data: {
        current_page: 1;
        data: TProduct[];
        first_page_url: string | null;
        from: number;
        last_page: number;
        last_page_url: string | null;
        links: {
            url: string | null;
            label: string;
            active: boolean;
        }[];
        next_page_url: string | null;
        path: string;
        per_page: number;
        prev_page_url: string | null;
        to: number;
        total: number;
    };
}
