var system=require("../../system")
var settings=require("../../../config/settings");
const CtlBase = require("../ctl.base");
const uuidv4 = require('uuid/v4');
class MirrorinfoCtl extends CtlBase{
   constructor(){
     super(CtlBase.getServiceName(MirrorinfoCtl));
     //this.appS=system.getObject("service.appSve");
   }

   async initNewInstance(queryobj,qobj){
     var u=uuidv4();
     var aid=u.replace(/\-/g,"");
     var rd={name:"",appid:aid}
     return system.getResult2(rd,null);
   }
   async createData(queryobj,pobj,req){

console.log("************************************createData");
     var refQueryObj={
       code_id:pobj.id,
       versions_num:pobj.versions_num
     }
    var refQueryResult= await this.service.refQuery(refQueryObj);
    if(refQueryResult.length>0){
        var tmpResult={
          state:-100
        }
      return system.getResult2(tmpResult,null);
    }

     //TODO:创建镜像脚本==
     var mirrorinfoItem={
       name:pobj.name+"-镜像",
       docker_repo_addr:pobj.docker_repo_addr,
       code_id:pobj.id,
       versions_num:pobj.versions_num
     };
    var result= await this.service.create(mirrorinfoItem);
    return system.getResult2(result,null);
   }
}
module.exports=MirrorinfoCtl;
