import { type PillsProps } from '@material-hu/components/design-system/Pills/types';

import { type Attachment } from 'src/types/attachments';
import { type Pagination } from 'src/types/services';

import { type ExchangesTab } from './constants';

export type ExchangesTabValue =
  (typeof ExchangesTab)[keyof typeof ExchangesTab];

export type ProductCategory = {
  id: number;
  name: string;
  deleted?: boolean;
};

export type Product = {
  id: number;
  name: string;
  cost: number;
  coverPicture: string | null;
  description: string | null;
  category: ProductCategory | null;
  attachments: Attachment[];
  deleted?: boolean;
};

export type ProductWithPeriod = {
  startDate: string | null;
  endDate: string | null;
  product: Product;
};

export type ProductsResponse = Pagination<ProductWithPeriod[]>;

export type GetProductsParams = {
  page: number;
  limit: number;
};

export const ExchangeStatus = {
  PENDING_DELIVERY: 'pending_delivery',
  DELIVERED: 'delivered',
  EXPIRED: 'expired',
} as const;

export type ExchangeStatus =
  (typeof ExchangeStatus)[keyof typeof ExchangeStatus];

export type ExchangeProduct = {
  id: number;
  name: string;
  cost: number;
  coverPicture: string | null;
};

export type Exchange = {
  id: number;
  cost: number;
  productId: number;
  product: ExchangeProduct;
  createdAt: string;
  // Translated status label. When the exchange window has expired the backend
  // sets this to "expired" while `statusWithoutTranslation` keeps the original
  // delivery state, so expiration must be detected through `status`.
  status: string;
  statusWithoutTranslation: ExchangeStatus;
};

export type ExchangePill = {
  type: NonNullable<PillsProps['type']>;
  labelKey: string;
};
