package app_user

import (
	"github.com/veypi/vbase/cfg"
	"github.com/veypi/vbase/models"
	"github.com/veypi/vigo"
)

type createOpts struct {
	AppID  string `src:"path@app_id" desc:"应用ID"`
	UserID string `json:"user_id" src:"json" desc:"用户ID"`
	Status string `json:"status" src:"json" desc:"状态" default:"ok"`
}

var _ = Router.Post("/", "创建应用用户", createAppUser)

func createAppUser(x *vigo.X, opts *createOpts) (*models.AppUser, error) {
	appUser := &models.AppUser{
		AppID:  opts.AppID,
		UserID: opts.UserID,
		Status: opts.Status,
	}

	if err := cfg.DB().Create(appUser).Error; err != nil {
		return nil, err
	}

	return appUser, nil
}
