<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.erp.supplier.repository.SupplierBankAccountRepository">

    <resultMap id="BaseResultMap" type="com.erp.supplier.entity.SupplierBankAccount">
        <id column="id" property="id"/>
        <result column="supplier_id" property="supplierId"/>
        <result column="account_name" property="accountName"/>
        <result column="bank_name" property="bankName"/>
        <result column="bank_account" property="bankAccount"/>
        <result column="branch_name" property="branchName"/>
        <result column="branch_code" property="branchCode"/>
        <result column="province" property="province"/>
        <result column="city" property="city"/>
        <result column="account_type" property="accountType"/>
        <result column="is_default" property="isDefault"/>
        <result column="balance" property="balance"/>
        <result column="reserved_phone" property="reservedPhone"/>
        <result column="remark" property="remark"/>
        <result column="created_at" property="createdAt"/>
        <result column="updated_at" property="updatedAt"/>
        <result column="deleted" property="deleted"/>
    </resultMap>

    <select id="selectBySupplierId" resultMap="BaseResultMap">
        SELECT * FROM supplier_bank_accounts
        WHERE supplier_id = #{supplierId} AND deleted = 0
        ORDER BY is_default DESC, created_at DESC
    </select>

    <select id="selectDefaultAccount" resultMap="BaseResultMap">
        SELECT * FROM supplier_bank_accounts
        WHERE supplier_id = #{supplierId} AND is_default = 1 AND deleted = 0
        LIMIT 1
    </select>

</mapper>
