package com.ecep.contract.ds.contract.repository;

import org.springframework.stereotype.Repository;

import com.ecep.contract.ContractFileType;
import com.ecep.contract.ds.other.repository.BaseEnumEntityRepository;
import com.ecep.contract.model.ContractFileTypeLocal;

@Repository
public interface ContractFileTypeLocalRepository
        extends BaseEnumEntityRepository<ContractFileType, ContractFileTypeLocal, Integer> {
    @Override
    default ContractFileType[] getEnumConstants() {
        return ContractFileType.values();
    }

    @Override
    default ContractFileTypeLocal newEntity() {
        return new ContractFileTypeLocal();
    }

    ContractFileTypeLocal findByTypeAndLang(ContractFileType type, String lang);

    default ContractFileTypeLocal getCompleteByTypeAndLang(ContractFileType type, String lang) {
        ContractFileTypeLocal v = findByTypeAndLang(type, lang);
        if (v == null) {
            v = newEntity();
            v.setType(type);
            v.setLang(lang);
            v.setValue(type.name());
            v = save(v);
        }
        return v;
    }
}