package model

import (
	"encoding/json"

	comM "github.com/pingcap/test-infra/common/model"
	reqM "github.com/pingcap/test-infra/common/model/tcms/request"
)

type Header struct {
	ApiVersion string `yaml:"apiVersion,omitempty"`
	Kind       string `yaml:"kind"`
}

type RawContent map[string]interface{}

func (doc RawContent) UnMarshal(obj interface{}) error {
	buffer, err := json.Marshal(doc)
	if err != nil {
		return err
	}
	return json.Unmarshal(buffer, obj)
}

type Resource struct {
	Header     `yaml:"header,inline"`
	ID         comM.ID `yaml:"id,omitempty"`
	RawContent `yaml:"content,inline"`
}

type OneShotPlan struct {
	Header                 `yaml:"header,inline"`
	reqM.PlanCreateRequest `yaml:"plan,inline"`
	Parameters             []comM.PlanVarBind `yaml:"parameters,omitempty"`
}

type OneShotPlanCases struct {
	Pipeline []OneShotPlanStep `json:"pipeline" validate:"required,gt=0"`
}

type OneShotPlanStep struct {
	Name string                 `json:"name"`
	Case reqM.CaseCreateRequest `json:"case"` // todo hook Unmarshal
}

type AuthUser struct {
	Name  string `json:"name"`
	Token string `json:"token"`
}
