import { AuctionEnquiryStatus } from '@/enums/auctionEnquiryStatus';
import { AuctionStatus } from '@/enums/auctionStatus';
import { MarketplaceListingAddonGridStatus } from '@/enums/marketplaceListingAddonGridStatus';
import { MarketplaceListingStatus } from '@/enums/marketplaceListingStatus';
import { MarketplaceListingType } from '@/enums/marketplaceListingType';
import type { StatusChipColor } from '@/types/statusChip';

export function booleanLabel(value: boolean): string {
    return value ? 'Yes' : 'No';
}

export interface PlanTypeOption {
    id: string;
    name: string;
}

export const planTypeOptions: PlanTypeOption[] = [
    { id: 'sell', name: 'Sell' },
    { id: 'buy', name: 'Buy' },
    { id: 'auction', name: 'Auction' },
];

export function planTypeLabel(value: string): string {
    return planTypeOptions.find((option) => option.id === value)?.name ?? value;
}

export interface SelectOption {
    id: string | null;
    name: string;
}

export const customerWebsiteOptions: SelectOption[] = [
    { id: null, name: 'All' },
    { id: 'marketplace', name: 'Marketplace' },
    { id: 'auctions', name: 'Auctions' },
];

export const customerStatusOptions: SelectOption[] = [
    { id: 'all', name: 'All' },
    { id: 'active', name: 'Active' },
    { id: 'inactive', name: 'Inactive' },
];

export const auctionEnquiryCategoryOptions: SelectOption[] = [
    { id: 'all', name: 'All' },
    { id: 'plate', name: 'Plate' },
    { id: 'car', name: 'Car' },
    { id: 'car_parts_memorabilia', name: 'Car Parts & Memorabilia' },
];

export const auctionEnquiryStatusOptions: SelectOption[] = [
    { id: 'all', name: 'All' },
    { id: AuctionEnquiryStatus.Pending, name: 'Pending' },
    { id: AuctionEnquiryStatus.Listed, name: 'Listed' },
    { id: AuctionEnquiryStatus.Rejected, name: 'Rejected' },
];

export const onlineAuctionStatusOptions: SelectOption[] = [
    { id: 'all', name: 'All' },
    { id: AuctionStatus.Published, name: 'Live' },
    { id: AuctionStatus.Sold, name: 'Sold' },
    { id: AuctionStatus.NotSold, name: 'Not sold' },
    { id: AuctionStatus.Cancelled, name: 'Cancelled' },
    { id: AuctionStatus.Scheduled, name: 'Scheduled' },
];

export const marketplaceListingTypeOptions: SelectOption[] = [
    { id: 'all', name: 'All' },
    { id: MarketplaceListingType.Sell, name: 'Sell' },
    { id: MarketplaceListingType.Buy, name: 'Buy' },
];

export const marketplaceListingStatusOptions: SelectOption[] = [
    { id: 'all', name: 'All' },
    { id: MarketplaceListingStatus.Draft, name: 'Drafted' },
    { id: MarketplaceListingStatus.Published, name: 'Published' },
    { id: MarketplaceListingStatus.Sold, name: 'Sold' },
    { id: MarketplaceListingStatus.Bought, name: 'Bought' },
    { id: MarketplaceListingStatus.Archived, name: 'Archived' },
    { id: MarketplaceListingStatus.Cancelled, name: 'Cancelled' },
];

export const marketplaceListingPlanOptions: SelectOption[] = [
    { id: 'all', name: 'All' },
    { id: '1', name: 'Standard' },
    { id: '2', name: 'Premium' },
    { id: '6', name: 'Premium Subscription' },
];

export const marketplaceListingAddonStatusOptions: SelectOption[] = [
    { id: 'all', name: 'All' },
    { id: MarketplaceListingAddonGridStatus.Completed, name: 'Completed' },
    { id: MarketplaceListingAddonGridStatus.Pending, name: 'Pending' },
    { id: MarketplaceListingAddonGridStatus.None, name: 'No' },
];

export const marketplaceListingRelistedOptions: SelectOption[] = [
    { id: 'all', name: 'All' },
    { id: 'yes', name: 'Relisted' },
];

export const marketplaceListingEditableStatusOptions: SelectOption[] = [
    { id: MarketplaceListingStatus.Draft, name: 'Drafted' },
    { id: MarketplaceListingStatus.Published, name: 'Published' },
    { id: MarketplaceListingStatus.Sold, name: 'Sold' },
    { id: MarketplaceListingStatus.Bought, name: 'Bought' },
    { id: MarketplaceListingStatus.Archived, name: 'Archived' },
    { id: MarketplaceListingStatus.Cancelled, name: 'Cancelled' },
];

export function marketplaceListingStatusOptionsForType(type: string): SelectOption[] {
    return marketplaceListingEditableStatusOptions.filter((option) => {
        if (type === MarketplaceListingType.Sell && option.id === MarketplaceListingStatus.Bought) {
            return false;
        }

        if (type === MarketplaceListingType.Buy && option.id === MarketplaceListingStatus.Sold) {
            return false;
        }

        return true;
    });
}

export const inPersonAuctionStatusOptions: SelectOption[] = [
    { id: 'all', name: 'All' },
    { id: AuctionStatus.Scheduled, name: 'Scheduled' },
    { id: AuctionStatus.Queued, name: 'Queued' },
    { id: AuctionStatus.Published, name: 'Live' },
    { id: AuctionStatus.Sold, name: 'Sold' },
    { id: AuctionStatus.PassedIn, name: 'Passed in' },
    { id: AuctionStatus.NotSold, name: 'Not sold' },
    { id: AuctionStatus.Cancelled, name: 'Cancelled' },
];

export {
    auctionReportFormatOptions,
    auctionReportStatusOptions,
    auctionReportStatusOptionsForFormat,
    auctionReportYesNoOptions,
} from '@/constants/auctionReportOptions';

export function auctionCategoryChipKey(category: string): string {
    if (category === 'car') {
        return 'car';
    }

    if (category === 'car_parts_memorabilia') {
        return 'parts';
    }

    return 'plate';
}

export function createAuctionPreviewStatus(isScheduled: boolean): {
    status: string;
    label: string;
    color: StatusChipColor;
} {
    if (isScheduled) {
        return { status: AuctionStatus.Scheduled, label: 'Scheduled', color: 'red' };
    }

    return { status: AuctionStatus.Published, label: 'Live', color: 'orange' };
}

export function createInPersonAuctionPreviewStatus(isScheduled: boolean): {
    status: string;
    label: string;
    color: StatusChipColor;
} {
    if (isScheduled) {
        return { status: AuctionStatus.Scheduled, label: 'Scheduled', color: 'red' };
    }

    return { status: AuctionStatus.Queued, label: 'Queued', color: 'grey' };
}

export const auctionPeriodTypeOptions: SelectOption[] = [
    { id: 'days', name: 'Days' },
    { id: 'hours', name: 'Hours' },
    { id: 'minutes', name: 'Minutes' },
];

export const australianStateOptions: SelectOption[] = [
    { id: 'ACT', name: 'ACT' },
    { id: 'NSW', name: 'NSW' },
    { id: 'NT', name: 'NT' },
    { id: 'QLD', name: 'QLD' },
    { id: 'SA', name: 'SA' },
    { id: 'TAS', name: 'TAS' },
    { id: 'VIC', name: 'VIC' },
    { id: 'WA', name: 'WA' },
];

export const plateWidthOptions: SelectOption[] = [
    { id: 'fixed', name: 'Fixed' },
    { id: 'variable', name: 'Variable' },
];

export const plateDisplayPositionOptions: SelectOption[] = [
    { id: 'left', name: 'Left' },
    { id: 'top', name: 'Top' },
    { id: 'bottom', name: 'Bottom' },
];

export const carBodyTypeOptions: SelectOption[] = [
    { id: 'coupe', name: 'Coupe' },
    { id: 'sedan', name: 'Sedan' },
    { id: 'hatch', name: 'Hatch' },
    { id: 'convertible', name: 'Convertible' },
    { id: 'suv', name: 'SUV' },
    { id: 'wagon', name: 'Wagon' },
];

export const carTransmissionOptions: SelectOption[] = [
    { id: 'manual', name: 'Manual' },
    { id: 'automatic', name: 'Automatic' },
];

export const carDoorOptions: number[] = [1, 2, 3, 4, 5];

export const carDriveSideOptions: SelectOption[] = [
    { id: 'rhd', name: 'RHD' },
    { id: 'lhd', name: 'LHD' },
];

export function identityVerificationLabel(
    verification: CustomerIdentityVerification | null,
): string {
    if (verification === null) {
        return '';
    }

    if (verification.success) {
        return 'Verified';
    }

    if (!verification.submitted) {
        return 'Not Submitted';
    }

    if (verification.error) {
        return 'Unverified';
    }

    return '';
}

export interface CustomerIdentityVerification {
    submitted: boolean;
    success: boolean;
    error: boolean;
}
