package com.nokia.sms.dao;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.type.JdbcType;

import com.nokia.common.mybatis.JsonTypeHandler;
import com.nokia.sms.pojo.Sms;

@Mapper
public interface SmsDao {

        @Insert("insert into sqmdb_rpt.sms_record (id, from_system, login_names, phone_numbers, content, schedule_time, sms_type, internal_id, result, send_time, status)"
                        + " values (#{id}, #{fromSystem}, #{loginNames, jdbcType=VARCHAR, typeHandler=com.nokia.common.mybatis.JsonTypeHandler},"
                        + " #{phoneNumbers, jdbcType=VARCHAR, typeHandler=com.nokia.common.mybatis.JsonTypeHandler}, #{content},"
                        + " #{scheduleTime}, #{smsType}, #{internalId}, #{result}, #{sendTime}, #{status})")
        void insert(Sms sms);

        @Results({
                        @Result(column = "id", property = "id"),
                        @Result(column = "from_system", property = "fromSystem"),
                        @Result(column = "login_names", property = "loginNames", jdbcType = JdbcType.VARCHAR, javaType = String[].class, typeHandler = JsonTypeHandler.class),
                        @Result(column = "phone_numbers", property = "phoneNumbers", jdbcType = JdbcType.VARCHAR, javaType = String[].class, typeHandler = JsonTypeHandler.class),
                        @Result(column = "content", property = "content"),
                        @Result(column = "schedule_time", property = "scheduleTime"),
                        @Result(column = "sms_type", property = "smsType"),
                        @Result(column = "internal_id", property = "internalId"),
                        @Result(column = "result", property = "result"),
                        @Result(column = "send_time", property = "sendTime"),
                        @Result(column = "status", property = "status"),
        })
        @Select("select * from sqmdb_rpt.sms_record where id = #{id}")
        Sms selectById(String id);
}
