import { IDocsSchemaType } from '@/modules/form/types';
import {
    DocumentsType,
    DocumentVariantsValue,
    IDocumentFieldsOptions,
} from '@/modules/documents/type';
import {
    useInnFieldsScheme,
    useLicensePlateFieldsScheme,
    useVUFieldsScheme,
    usePassportFieldsScheme,
    usePatentFieldsScheme,
    useMedicalBookFieldsScheme,
    useVNGFieldsScheme,
    useRVPFieldsScheme,
    useFsspFieldsScheme,
} from '@/modules/documents';

export function useDefaultFields(
    documentVariant: DocumentVariantsValue,
    customDocsSchemaType?: IDocsSchemaType[],
    fieldsOptions?: IDocumentFieldsOptions,
) {
    const DEFAULT_FIELDS: Record<DocumentVariantsValue, IDocsSchemaType[]> = {
        [DocumentsType.INN]: useInnFieldsScheme(),
        [DocumentsType.LICENCE_PLATE]: useLicensePlateFieldsScheme(fieldsOptions?.licensePlate),
        [DocumentsType.DRIVERS_LICENSE]: useVUFieldsScheme(),
        [DocumentsType.NONRESIDENT_PASSPORT]: usePassportFieldsScheme(fieldsOptions?.passport),
        [DocumentsType.PATENT]: usePatentFieldsScheme(fieldsOptions?.patent),
        [DocumentsType.VNG]: useVNGFieldsScheme(),
        [DocumentsType.RVP]: useRVPFieldsScheme(),
        [DocumentsType.MEDICAL_BOOK]: useMedicalBookFieldsScheme(),
        [DocumentsType.FSSP]: useFsspFieldsScheme(fieldsOptions?.fssp),
        [DocumentsType.CUSTOM]: customDocsSchemaType
            ? customDocsSchemaType
            : ({} as IDocsSchemaType[]),
    };

    return (
        DEFAULT_FIELDS[documentVariant] ||
        (customDocsSchemaType?.length && DEFAULT_FIELDS[DocumentsType.CUSTOM]) ||
        []
    );
}
