import { Status } from '../types';
import { Pagination, UpdatedBy, CreatedBy } from 'stores/types';

export type ServiceAndProduct =
  | (Service & { type: 'service' })
  | (ProductList & { type: 'product' });

export interface TreeProduct {
  name: string;
  id: string;
  code: string;
  type?: 'group' | 'type';
  [x: string]: any;
}

export interface Service {
  productTypeId: string;
  updatedAt: string;
  updatedBy: UpdatedBy;
  createdAt: string;
  createdBy: CreatedBy;
  status: Status;
  attributes: Attributes;
  detail: string;
  name: string;
  code: string;
  id: string;
  work: Work[];
  imageUrl: string;
  registeredBranchId: string;
}

export interface WorkCreate {
  attributes: Attributes;
  productId: string[];
  name: string;
  order: number;
}

export interface Work {
  id: string;
  order: number;
  name: string;
  attributes: Attributes;
  status: Status;
  serviceId: string;
  createdBy: string | null;
  createdAt: string;
  updatedBy: string | null;
  updatedAt: string;
}

export interface ServiceCreate {
  work: {
    attributes: Attributes;
    productId: string[];
    name: string;
  }[];
  attributes: Attributes;
  detail: string;
  name: string;
  code: string;
  image?: File;
  status?: Status;
  productTypeId: string;
  registeredBranchId: string | null;
}

export interface Attributes {
  showTotalPrice?: boolean;
  additional: (PropString | PropNumber | PropDate | PropOptions)[];
}

type PropString = {
  type: 'string';
  fieldName: string;
  isPhoneNumber: boolean;
  phoneNumberLength: number;
};

type PropNumber = {
  type: 'number';
  fieldName: string;
  comma: boolean;
  decimal: boolean;
  decimalPlace: number;
};

type PropDate = {
  type: 'date';
  fieldName: string;
};

type PropOptions = {
  type: 'array';
  fieldName: string;
  options: string[];
};

//  Product

export interface ServiceById {
  work: (Work & { productOnWork: ProductOnWork[] })[];
  updatedAt: string;
  updatedBy: UpdatedBy;
  createdAt: string;
  createdBy: CreatedBy;
  status: Status;
  attributes: Attributes;
  detail: string;
  name: string;
  code: string;
  id: string;
  imageUrl: 'string';
  productTypeId: string;
  registeredBranchId: string;
}

export interface ProductOnWork {
  product: ProductList;
  registeredBranchId: string;
  updatedAt: string;
  updatedBy: UpdatedBy;
  createdAt: string;
  createdBy: CreatedBy;
  productId: string;
  workId: string;
  order: number;
}

export interface WorkItems {
  id: string;
  name: string;
  attributes: Attributes;
  product: (ProductList & { nameEn: string })[];
}

export interface ProductList {
  remark: string;
  updatedAt: string;
  updatedBy: UpdatedBy;
  createdAt: string;
  createdBy: CreatedBy;
  productTypeId: string;
  status: Status;
  serviceCharge: number;
  agentPrice: number;
  price: number;
  process: number;
  detail: string;
  name: string;
  code: string;
  id: string;
  imageUrl: string;
  registeredBranchId: string;
}

export interface ProductCreate {
  registeredBranchId: string;
  productTypeId: string;
  remark: string;
  serviceCharge: number;
  agentPrice: number;
  price: number;
  process: number;
  detail: string;
  name: string;
  code: string;
  image?: File;
  status?: Status;
}

export interface ProductUpdate {
  productTypeId: string;
  remark: string;
  serviceCharge: number;
  agentPrice: number;
  price: number;
  process: string;
  detail: string;
  name: string;
  image?: File;
  status?: Status;
}

//
export type ProductGroup = {
  id: string;
  code: string;
  name: string;
  detail: string;
  remark: string;
  status: Status;
  createdBy: CreatedBy;
  createdAt: string;
  updatedBy: UpdatedBy;
  updatedAt: string;
  _count: { product: number; type: number; service: number };
};

export interface ProductGroupCreate {
  remark: string;
  detail: string;
  name: string;
  code: string;
}

export interface ProductGroupUpdate {
  remark: string;
  detail: string;
  name: string;
  code: string;
  status: Status;
}
