package com.erp.supplier.dto.response;

import com.erp.supplier.entity.SupplierBankAccount;
import lombok.Data;
import lombok.Builder;
import java.math.BigDecimal;
import java.time.LocalDateTime;

@Data
@Builder
public class SupplierBankAccountResponse {

    private Long id;
    private Long supplierId;
    private String accountName;
    private String bankName;
    private String bankAccount;
    private String branchName;
    private String branchCode;
    private String province;
    private String city;
    private String accountType;
    private String accountTypeText;
    private Integer isDefault;
    private BigDecimal balance;
    private String reservedPhone;
    private String remark;
    private LocalDateTime createdAt;
    private LocalDateTime updatedAt;

    public static SupplierBankAccountResponse fromEntity(SupplierBankAccount account) {
        return SupplierBankAccountResponse.builder()
                .id(account.getId())
                .supplierId(account.getSupplierId())
                .accountName(account.getAccountName())
                .bankName(account.getBankName())
                .bankAccount(account.getBankAccount())
                .branchName(account.getBranchName())
                .branchCode(account.getBranchCode())
                .province(account.getProvince())
                .city(account.getCity())
                .accountType(account.getAccountType())
                .accountTypeText(getAccountTypeText(account.getAccountType()))
                .isDefault(account.getIsDefault())
                .balance(account.getBalance())
                .reservedPhone(account.getReservedPhone())
                .remark(account.getRemark())
                .createdAt(account.getCreatedAt())
                .updatedAt(account.getUpdatedAt())
                .build();
    }

    public static String getAccountTypeText(String type) {
        if (type == null) return "";
        switch (type) {
            case "basic": return "基本户";
            case "general": return "一般户";
            case "reserve": return "保证金户";
            default: return type;
        }
    }
}
