/**
 * Created by MyPC on 2019/11/5.
 */
'use strict';
const hash= require('../class/hash');
const Sequelize = require('sequelize');
const Op = Sequelize.Op;

module.exports = (sequelize, DataTypes) => {
    const curing = sequelize.define('cloud_curing', {

        mobile: DataTypes.STRING,
        sso_id: DataTypes.STRING,
        compilation_id: DataTypes.STRING,
        curingCompany: DataTypes.STRING,
        sid: DataTypes.INTEGER,
        cid: DataTypes.INTEGER,
        status: DataTypes.INTEGER,
        client_id: DataTypes.INTEGER,
        addtime: DataTypes.STRING,
        updateTotal:DataTypes.INTEGER,
        upgradeDescribe: DataTypes.STRING,

    }, {});
    curing.associate = function(models) {
        // associations can be defined here
    };

    
    curing.getCuringInMobile=async function(mobile,compilation_id){
    	
    	if(!hash.isExistence(mobile)){
    		return [];
        }
    	
    
    	var option={
        		where: {
        			mobile: {
                        [Op.or]: [mobile]
        					}
        				},
                raw:true,
                };
        if(hash.isExistence(compilation_id)){
            option.where={compilation_id: compilation_id};
        }
    	
        var curingList = await this.findAll(option);
        return curingList;
    };
    

    /*
     * ����mobile����Ѱ������ư��û�
     * */
    curing.getCuringByMobile=async function(mobile){

        if(mobile==undefined){
            return [];
        }
        var condition={
            raw:true,
            where: {
                mobile: mobile
            }};
        var curingList = await this.findOne(condition);
        return curingList;
    };

    /*
     * ����ssoid����Ѱ������ư��û�
     * */
    curing.getCuringBySsoid=async function(ssoid){
        if(!hash.isExistence(ssoid)){
            return [];
        }

        var condition={
            raw:true,
            where: {
                sso_id: ssoid
            }};
        var detail = await this.findOne(condition);
        if(!hash.isExistence(detail)){
            return [];
        }
        detail.id=hash.hashEncode(detail.id.toString());
        return detail;
    };

    /*
     * ����id����Ѱ������ư��û�
     * */
    curing.getCuringById=async function(id){
        if(!hash.isExistence(id)){
            return [];
        }
        var condition={
            raw:true,
            where: {
                id: id
            }};
        var detail = await this.findOne(condition);
        return detail;
    };

    /*
     * ��ñ��ر��
     * */
    curing.getCuringCompilationList=async function(){

        return [];
    };

    return curing;
};