import type {
	PricingLevel,
	Product,
	PrepareImportFileResponse,
} from '../typings/types';

export interface ImportCounts {
	products: number;
	pricingLevels: number;
}

export type Views =
	| 'pricing-rules'
	| 'importer.field-mappings-form'
	| 'importer.csv-import-form';

export interface PricingRuleSlice {
	products: Product[] | null;
	activeProductId: string | null;
	activePricingLevelId: string | null;
	hasUnsavedChanges: boolean;
	setProducts: (products: Product[]) => void;
	getProductsWithPricingLevels: () => Product[];
	initializeProductPricingLevels: (productId: string) => void;
	addProductPricingLevel: (productId: number) => void;
	setActiveProductId: (id: number | null) => void;
	setActivePricingLevel: (id: string | null) => void;
	getActivePricingLevel: () => PricingLevel | null;
	updateActiveProductPricingLevel: (pricingLevel: PricingLevel) => void;
	deleteActiveProductPricingLevel: (pricingLevelId: string) => void;
	setHasUnsavedChanges: (hasUnsavedChanges: boolean) => void;
	setPricingLevelOrder: (
		productId: number,
		pricingLevels: PricingLevel[]
	) => void;
	importCounts: ImportCounts | null;
	setImportCounts: (counts: ImportCounts | null) => void;
	savePricingLogic: (products: Product[]) => Promise<void>;
}

export interface ImporterSlice {
	filePath: string | null;
	disambiguation: PrepareImportFileResponse['data']['disambiguation'] | null;
	fileContents: Array<Array<string>> | null;
	setFilePath: (filePath: string) => void;
	setDisambiguation: (
		disambiguation: PrepareImportFileResponse['data']['disambiguation']
	) => void;
	setFileContents: (fileContents: Array<Array<string>>) => void;
	clearStore: () => void;
}

export interface ViewSlice {
	activeView: Views;
	setActiveView: (view: Views) => void;
}

export type BannerType = 'success' | 'error';
export interface Banner {
	uuid: string;
	content: string;
	type: BannerType;
}
export interface BannersSlice {
	banners: Banner[];
	addBanner: (content: string, type?: BannerType) => void;
	removeBanner: (banner: Banner) => void;
}

export type CombinedStore = PricingRuleSlice &
	ImporterSlice &
	ViewSlice &
	BannersSlice;
