package com.social.media.dto;

import jakarta.validation.constraints.*;

import java.time.LocalDateTime;

public class CompanyDto {
    
    private Long id;
    private String companyCode;
    
    @NotBlank(message = "Nome é obrigatório")
    @Size(min = 2, max = 200, message = "Nome deve ter entre 2 e 200 caracteres")
    private String name;
    
    @NotBlank(message = "Email é obrigatório")
    @Email(message = "Email deve ter formato válido")
    @Size(max = 100, message = "Email deve ter no máximo 100 caracteres")
    private String email;
    
    @NotBlank(message = "CNPJ é obrigatório")
    @Pattern(regexp = "^\\d{2}\\.\\d{3}\\.\\d{3}/\\d{4}-\\d{2}$", message = "CNPJ deve ter formato válido (XX.XXX.XXX/XXXX-XX)")
    private String cnpj;
    
    @Size(max = 20, message = "Telefone deve ter no máximo 20 caracteres")
    private String phone;
    
    @Size(max = 255, message = "Website deve ter no máximo 255 caracteres")
    private String website;
    
    @Size(max = 100, message = "Setor de atividade deve ter no máximo 100 caracteres")
    private String activitySector;
    
    private String plan; // CompanyPlan enum as string
    private String status; // CompanyStatus enum as string
    
    // Hierarchy fields
    private Long parentCompanyId;
    
    @Min(value = 0, message = "Nível hierárquico deve ser no mínimo 0")
    @Max(value = 5, message = "Nível hierárquico deve ser no máximo 5")
    private Integer hierarchyLevel;
    
    private String branchType; // CompanyBranchType enum as string
    
    @Pattern(regexp = "^[A-Z0-9]{3,10}$", message = "Código da filial deve ter formato válido (3-10 caracteres alfanuméricos maiúsculos)")
    private String branchCode;
    
    @Size(max = 100, message = "Região deve ter no máximo 100 caracteres")
    private String region;
    
    private String branchStatus; // CompanyBranchStatus enum as string
    
    // Audit fields
    private LocalDateTime createdAt;
    private LocalDateTime updatedAt;
    private Long createdBy;
    private Long updatedBy;
    private Long version;
    
    private AddressDto address;
    
    public CompanyDto() {}
    
    public CompanyDto(String name, String email, String cnpj) {
        this.name = name;
        this.email = email;
        this.cnpj = cnpj;
        this.createdAt = LocalDateTime.now();
    }
    
    public CompanyDto(Long id, String name, String email, String cnpj, String plan, String status) {
        this.id = id;
        this.name = name;
        this.email = email;
        this.cnpj = cnpj;
        this.plan = plan;
        this.status = status;
        this.createdAt = LocalDateTime.now();
    }
    
    public static class AddressDto {
        @Size(max = 200, message = "Rua deve ter no máximo 200 caracteres")
        private String street;
        
        @Size(max = 20, message = "Número deve ter no máximo 20 caracteres")
        private String number;
        
        @Size(max = 100, message = "Complemento deve ter no máximo 100 caracteres")
        private String complement;
        
        @Size(max = 100, message = "Bairro deve ter no máximo 100 caracteres")
        private String neighborhood;
        
        @Size(max = 100, message = "Cidade deve ter no máximo 100 caracteres")
        private String city;
        
        @Size(max = 50, message = "Estado deve ter no máximo 50 caracteres")
        private String state;
        
        @Size(max = 10, message = "CEP deve ter no máximo 10 caracteres")
        private String zipCode;
        
        @Size(max = 50, message = "País deve ter no máximo 50 caracteres")
        private String country;
        
        public AddressDto() {}
        
        public AddressDto(String street, String number, String city, String state, String zipCode) {
            this.street = street;
            this.number = number;
            this.city = city;
            this.state = state;
            this.zipCode = zipCode;
        }
        
        // Getters e Setters
        public String getStreet() { return street; }
        public void setStreet(String street) { this.street = street; }
        
        public String getNumber() { return number; }
        public void setNumber(String number) { this.number = number; }
        
        public String getComplement() { return complement; }
        public void setComplement(String complement) { this.complement = complement; }
        
        public String getNeighborhood() { return neighborhood; }
        public void setNeighborhood(String neighborhood) { this.neighborhood = neighborhood; }
        
        public String getCity() { return city; }
        public void setCity(String city) { this.city = city; }
        
        public String getState() { return state; }
        public void setState(String state) { this.state = state; }
        
        public String getZipCode() { return zipCode; }
        public void setZipCode(String zipCode) { this.zipCode = zipCode; }
        
        public String getCountry() { return country; }
        public void setCountry(String country) { this.country = country; }
    }
    
    // Getters e Setters
    public Long getId() { return id; }
    public void setId(Long id) { this.id = id; }
    
    public String getCompanyCode() { return companyCode; }
    public void setCompanyCode(String companyCode) { this.companyCode = companyCode; }
    
    public String getName() { return name; }
    public void setName(String name) { this.name = name; }
    
    public String getEmail() { return email; }
    public void setEmail(String email) { this.email = email; }
    
    public String getCnpj() { return cnpj; }
    public void setCnpj(String cnpj) { this.cnpj = cnpj; }
    
    public String getPhone() { return phone; }
    public void setPhone(String phone) { this.phone = phone; }
    
    public String getWebsite() { return website; }
    public void setWebsite(String website) { this.website = website; }
    
    public String getActivitySector() { return activitySector; }
    public void setActivitySector(String activitySector) { this.activitySector = activitySector; }
    
    public String getPlan() { return plan; }
    public void setPlan(String plan) { this.plan = plan; }
    
    public String getStatus() { return status; }
    public void setStatus(String status) { this.status = status; }
    
    public Long getParentCompanyId() { return parentCompanyId; }
    public void setParentCompanyId(Long parentCompanyId) { this.parentCompanyId = parentCompanyId; }
    
    public Integer getHierarchyLevel() { return hierarchyLevel; }
    public void setHierarchyLevel(Integer hierarchyLevel) { this.hierarchyLevel = hierarchyLevel; }
    
    public String getBranchType() { return branchType; }
    public void setBranchType(String branchType) { this.branchType = branchType; }
    
    public String getBranchCode() { return branchCode; }
    public void setBranchCode(String branchCode) { this.branchCode = branchCode; }
    
    public String getRegion() { return region; }
    public void setRegion(String region) { this.region = region; }
    
    public String getBranchStatus() { return branchStatus; }
    public void setBranchStatus(String branchStatus) { this.branchStatus = branchStatus; }
    
    public LocalDateTime getCreatedAt() { return createdAt; }
    public void setCreatedAt(LocalDateTime createdAt) { this.createdAt = createdAt; }
    
    public LocalDateTime getUpdatedAt() { return updatedAt; }
    public void setUpdatedAt(LocalDateTime updatedAt) { this.updatedAt = updatedAt; }
    
    public Long getCreatedBy() { return createdBy; }
    public void setCreatedBy(Long createdBy) { this.createdBy = createdBy; }
    
    public Long getUpdatedBy() { return updatedBy; }
    public void setUpdatedBy(Long updatedBy) { this.updatedBy = updatedBy; }
    
    public Long getVersion() { return version; }
    public void setVersion(Long version) { this.version = version; }
    
    public AddressDto getAddress() { return address; }
    public void setAddress(AddressDto address) { this.address = address; }
    
    // Utility methods
    public boolean isActive() {
        return "ACTIVE".equals(status);
    }
    
    public boolean isMatriz() {
        return "MATRIZ".equals(branchType);
    }
    
    public boolean hasParentCompany() {
        return parentCompanyId != null;
    }
}
