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

import org.springframework.stereotype.Repository;

import com.ecep.contract.CompanyFileType;
import com.ecep.contract.ds.other.repository.BaseEnumEntityRepository;
import com.ecep.contract.model.CompanyFileTypeLocal;

@Repository
public interface CompanyFileTypeLocalRepository extends BaseEnumEntityRepository<CompanyFileType, CompanyFileTypeLocal, Integer> {

    @Override
    default CompanyFileType[] getEnumConstants() {
        return CompanyFileType.values();
    }

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

    CompanyFileTypeLocal findByTypeAndLang(CompanyFileType type, String lang);

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