import {
  fiscalCodeValidator,
  mobileValidator,
  password,
  postalCodeValidator,
  usernameValidator,
} from '@/core/validators';
import { nationalIdValidator } from '@/core/validators/national-id.validator';
import { ValidatorFn, Validators } from '@angular/forms';

const required = () => [Validators.required] as ValidatorFn[];
type ControlConfig = [any, ValidatorFn[]];

export const fieldControl = {
  name: (value = '', isRequired = true): ControlConfig => [value, isRequired ? required() : []],
  invoice_template: (value = '', isRequired = true): ControlConfig => [
    value,
    isRequired ? required() : [],
  ],
  code: (value = '', isRequired = true): ControlConfig => [value, isRequired ? required() : []],
  description: (value = '', isRequired = false): ControlConfig => [
    value,
    isRequired ? required() : [],
  ],
  company_name: (value = '', isRequired = true): ControlConfig => [
    value,
    isRequired ? required() : [],
  ],
  first_name: (value = '', isRequired = true): ControlConfig => [
    value,
    isRequired ? required() : [],
  ],
  firstName: (value = '', isRequired = true): ControlConfig => [
    value,
    isRequired ? required() : [],
  ],
  last_name: (value = '', isRequired = true): ControlConfig => [
    value,
    isRequired ? required() : [],
  ],
  lastName: (value = '', isRequired = true): ControlConfig => [value, isRequired ? required() : []],
  legal_name: (value = '', isRequired = true): ControlConfig => [
    value,
    isRequired ? required() : [],
  ],
  registration_code: (value = '', isRequired = true): ControlConfig => [
    value,
    isRequired ? required() : [],
  ],
  registration_number: (value = '', isRequired = true): ControlConfig => [
    value,
    isRequired ? required() : [],
  ],
  mobile_number: (value = '', isRequired = true): ControlConfig => [
    value,
    isRequired ? [Validators.required, mobileValidator()] : [mobileValidator()],
  ],
  mobile: (value = '', isRequired = true): ControlConfig => [
    value,
    isRequired ? [Validators.required, mobileValidator()] : [mobileValidator()],
  ],
  email: (value = '', isRequired = false): ControlConfig => [
    value,
    isRequired ? [Validators.required, Validators.email] : [Validators.email],
  ],
  national_code: (value = '', isRequired = true): ControlConfig => [
    value,
    isRequired ? [Validators.required, nationalIdValidator()] : [nationalIdValidator()],
  ],
  national_id: (value = '', isRequired = true): ControlConfig => [
    value,
    isRequired ? [Validators.required, nationalIdValidator()] : [nationalIdValidator()],
  ],
  postal_code: (value = '', isRequired = false): ControlConfig => [
    value,
    isRequired ? [Validators.required, postalCodeValidator()] : [postalCodeValidator()],
  ],
  username: (value = '', isRequired = true): ControlConfig => [
    value,
    isRequired ? [...required(), usernameValidator()] : [usernameValidator()],
  ],
  economic_code: (value = '', isRequired = true): ControlConfig => [
    value,
    isRequired ? required() : [],
  ],
  fiscal_id: (value = '', isRequired = true): ControlConfig => [
    value,
    isRequired ? [Validators.required, fiscalCodeValidator()] : [fiscalCodeValidator()],
  ],
  partner_token: (value = '', isRequired = true): ControlConfig => [
    value,
    isRequired ? required() : [],
  ],
  invoice_number_sequence: (value = 1, isRequired = true): ControlConfig => [
    value,
    isRequired ? [Validators.required, Validators.min(1)] : [Validators.min(1)],
  ],
  guild_id: (value = '', isRequired = true): ControlConfig => [value, isRequired ? required() : []],
  license_starts_at: (value = '', isRequired = true): ControlConfig => [
    value,
    isRequired ? required() : [],
  ],
  branch_code: (value = '', isRequired = false): ControlConfig => [
    value,
    isRequired ? required() : [],
  ],
  address: (value = '', isRequired = true): ControlConfig => [value, isRequired ? required() : []],
  pos_type: (value = '', isRequired = true): ControlConfig => [value, isRequired ? required() : []],
  type: (value = '', isRequired = true): ControlConfig => [value, isRequired ? required() : []],
  role: (value = '', isRequired = true): ControlConfig => [value, isRequired ? required() : []],
  unit_type: (value = '', isRequired = true): ControlConfig => [
    value,
    isRequired ? required() : [],
  ],
  pricing_model: (value = '', isRequired = true): ControlConfig => [
    value,
    isRequired ? required() : [],
  ],
  gender: (value = '', isRequired = false): ControlConfig => [value, isRequired ? required() : []],
  legal: (value = '', isRequired = false): ControlConfig => [value, isRequired ? required() : []],
  individual: (value = '', isRequired = false): ControlConfig => [
    value,
    isRequired ? required() : [],
  ],
  partner_id: (value = '', isRequired = true): ControlConfig => [
    value,
    isRequired ? required() : [],
  ],
  brand_id: (value = '', isRequired = true): ControlConfig => [value, isRequired ? required() : []],
  category_id: (value = '', isRequired = true): ControlConfig => [
    value,
    isRequired ? required() : [],
  ],
  starts_at: (value = '', isRequired = true): ControlConfig => [
    value,
    isRequired ? required() : [],
  ],
  expires_at: (value = '', isRequired = true): ControlConfig => [
    value,
    isRequired ? required() : [],
  ],
  activated_expires_at: (value = '', isRequired = true): ControlConfig => [
    value,
    isRequired ? required() : [],
  ],
  invoiceDate: (value = '', isRequired = true): ControlConfig => [
    value,
    isRequired ? required() : [],
  ],
  quantity: (value = '', isRequired = true): ControlConfig => [value, isRequired ? required() : []],
  unit_price: (value = '', isRequired = true): ControlConfig => [
    value,
    isRequired ? required() : [],
  ],
  cash: (value = '', isRequired = false): ControlConfig => [value, isRequired ? required() : []],
  set_off: (value = '', isRequired = false): ControlConfig => [value, isRequired ? required() : []],
  setOff: (value = '', isRequired = false): ControlConfig => [value, isRequired ? required() : []],
  terminal: (value = '', isRequired = false): ControlConfig => [
    value,
    isRequired ? required() : [],
  ],
  sku: (value = '', isRequired = true): ControlConfig => [value, isRequired ? required() : []],
  VAT: (value = '', isRequired = true): ControlConfig => [value, isRequired ? required() : []],
  is_public: (value = 'true', isRequired = false): ControlConfig => [
    value,
    isRequired ? required() : [],
  ],
  is_domestic: (value = 'true', isRequired = false): ControlConfig => [
    value,
    isRequired ? required() : [],
  ],
  model: (value = '', isRequired = true): ControlConfig => [value, isRequired ? required() : []],
  serial_number: (value = '', isRequired = false): ControlConfig => [
    value,
    isRequired ? required() : [],
  ],
  device_id: (value = '', isRequired = false): ControlConfig => [
    value,
    isRequired ? required() : [],
  ],
  provider_id: (value = '', isRequired = false): ControlConfig => [
    value,
    isRequired ? required() : [],
  ],

  measure_unit: (value = '', isRequired = true): ControlConfig => [
    value,
    isRequired ? required() : [],
  ],

  password: (value = '', isRequired = true): ControlConfig => [
    value,
    isRequired ? [...required(), password()] : [password()],
  ],
  confirmPassword: (value = '', isRequired = true): ControlConfig => [
    value,
    isRequired ? required() : [],
  ],
};
