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

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

export interface Service {
  selectedImage?: string;
  productGroupId: 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 {
  id?: string;
  work: {
    attributes: Attributes;
    productId: string[];
    name: string;
  }[];
  attributes: Attributes;
  detail: string;
  name: string;
  code: string;
  image?: File;
  status?: Status;
  productGroupId: string;
  selectedImage?: string;
}

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';
  productGroupId: 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 {
  selectedImage?: string;
  expenseType: string;
  vatIncluded: boolean;
  remark: string;
  updatedAt: string;
  updatedBy: UpdatedBy;
  createdAt: string;
  createdBy: CreatedBy;
  productGroupId: string;
  status: Status;
  serviceCharge: number;
  agentPrice: number;
  price: number;
  process: number;
  detail: string;
  name: string;
  code: string;
  id: string;
  imageUrl: string;
}

export interface ProductCreate {
  id?: string;
  selectedImage?: string;
  expenseType: string;
  vatIncluded: boolean;
  productGroupId: string;
  remark: string;
  serviceCharge: number;
  agentPrice: number;
  price: number;
  process: number;
  detail: string;
  name: string;
  code: string;
  image?: File;
  status?: Status;
}

export interface ProductUpdate {
  selectedImage?: string;
  productGroupId: 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;
  registeredBranchId: string;
  createdBy: CreatedBy;
  createdAt: string;
  updatedBy: UpdatedBy;
  updatedAt: string;
  _count: { product: number; service: number };
};

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

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