package mobile_api_controllers

import (
	"XT_New/controllers"
	"XT_New/enums"
	"XT_New/models"
	"fmt"
)

type MobileBaseAPIController struct {
	controllers.BaseAPIController
}

func (this *MobileBaseAPIController) Prepare() {
	this.BaseAPIController.Prepare()
	// beego.Trace("============================================================")
	// beego.Trace("session ID: %v", this.Ctx.Input.Cookie("beegosessionID"))
	// beego.Trace("session : %v", this.GetSession("info"))
	// this.SetSession("info", time.Now().Format("2006/01/02 15:04:05"))
	// beego.Trace("============================================================")
}

func (this *MobileBaseAPIController) GetMobileAdminUserInfo() *MobileAdminUserInfo {
	userInfo := this.GetSession("mobile_admin_user_info")
	if userInfo == nil {
		return nil
	} else {
		return userInfo.(*MobileAdminUserInfo)
	}
}

type MobileAdminUserInfo struct {
	AdminUser    *models.AdminUser
	Org          *models.Org
	App          *models.OrgApp
	AppRole      *models.App_Role
	Subscibe     *models.ServeSubscibe
	TemplateInfo *models.GobalTemplate
}

type MobileBaseAPIAuthController struct {
	MobileBaseAPIController
}

func (this *MobileBaseAPIAuthController) Prepare() {
	this.MobileBaseAPIController.Prepare()

	adminUserInfo := this.GetMobileAdminUserInfo()
	fmt.Println(adminUserInfo)

	if adminUserInfo == nil {
		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotLogin)
		this.StopRun()
	}

	//if this.Ctx.Request.Method != "GET" {
	//	err := service.GetOrgSubscibeState(adminUserInfo.Subscibe)
	//	if err != nil || adminUserInfo.Subscibe.State == 3 {
	//		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotSubscibe)
	//		this.StopRun()
	//	}
	//}
}
