<?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="cn.reghao.tnb.account.app.db.mapper.oauth.ClientDetailsMapper">
    <insert id="save">
        insert into oauth_client_details
        (`client_id`,`resource_ids`,`client_secret`,`scope`,`authorized_grant_types`,`web_server_redirect_uri`,`authorities`,`access_token_validity`,`refresh_token_validity`,`additional_information`,`autoapprove`)
        values
        (#{clientId},#{resourceIds},#{clientSecret},#{scope},#{authorizedGrantTypes},#{webServerRedirectUri},#{authorities},#{accessTokenValidity},#{refreshTokenValidity},#{additionalInformation},#{autoapprove})
    </insert>

    <delete id="deleteByClientId">
        delete from oauth_client_details
        where client_id=#{clientId}
    </delete>

    <select id="findByOwner" resultType="cn.reghao.tnb.account.app.model.po.oauth.ClientDetails">
        select client.*
        from oauth_client_details client
        inner join oauth_user_oauth_app app
        on client.client_id=app.client_id and user_id=#{owner}
        limit 10
    </select>

    <select id="findByClientId" resultType="cn.reghao.tnb.account.app.model.po.oauth.ClientDetails">
        select *
        from oauth_client_details
        where client_id=#{clientId}
    </select>
</mapper>
