// Code generated by cmd/lexgen (see Makefile's lexgen); DO NOT EDIT.

package tangled

// schema: sh.tangled.ci.defs

import (
	"encoding/json"
	"fmt"

	"github.com/bluesky-social/indigo/lex/util"
)

const ()

// CiDefs_Pipeline is a "pipeline" in the sh.tangled.ci.defs schema.
type CiDefs_Pipeline struct {
	// commit: Commit Id this pipeline is running on
	Commit    string  `json:"commit" cborgen:"commit"`
	CreatedAt *string `json:"createdAt,omitempty" cborgen:"createdAt,omitempty"`
	// id: Spindle-local pipeline id
	Id string `json:"id" cborgen:"id"`
	// repo: Repository DID
	Repo *string `json:"repo,omitempty" cborgen:"repo,omitempty"`
	// trigger: Trigger event metadata
	Trigger *CiDefs_Pipeline_Trigger `json:"trigger" cborgen:"trigger"`
	// workflows: Triggered workflows
	Workflows []*CiDefs_Workflow `json:"workflows" cborgen:"workflows"`
}

// Trigger event metadata
type CiDefs_Pipeline_Trigger struct {
	CiTrigger_Push        *CiTrigger_Push
	CiTrigger_PullRequest *CiTrigger_PullRequest
	CiTrigger_Manual      *CiTrigger_Manual
}

func (t *CiDefs_Pipeline_Trigger) MarshalJSON() ([]byte, error) {
	if t.CiTrigger_Push != nil {
		t.CiTrigger_Push.LexiconTypeID = "sh.tangled.ci.trigger#push"
		return json.Marshal(t.CiTrigger_Push)
	}
	if t.CiTrigger_PullRequest != nil {
		t.CiTrigger_PullRequest.LexiconTypeID = "sh.tangled.ci.trigger#pullRequest"
		return json.Marshal(t.CiTrigger_PullRequest)
	}
	if t.CiTrigger_Manual != nil {
		t.CiTrigger_Manual.LexiconTypeID = "sh.tangled.ci.trigger#manual"
		return json.Marshal(t.CiTrigger_Manual)
	}
	return nil, fmt.Errorf("cannot marshal empty enum")
}
func (t *CiDefs_Pipeline_Trigger) UnmarshalJSON(b []byte) error {
	typ, err := util.TypeExtract(b)
	if err != nil {
		return err
	}

	switch typ {
	case "sh.tangled.ci.trigger#push":
		t.CiTrigger_Push = new(CiTrigger_Push)
		return json.Unmarshal(b, t.CiTrigger_Push)
	case "sh.tangled.ci.trigger#pullRequest":
		t.CiTrigger_PullRequest = new(CiTrigger_PullRequest)
		return json.Unmarshal(b, t.CiTrigger_PullRequest)
	case "sh.tangled.ci.trigger#manual":
		t.CiTrigger_Manual = new(CiTrigger_Manual)
		return json.Unmarshal(b, t.CiTrigger_Manual)

	default:
		return nil
	}
}

// CiDefs_Workflow is a "workflow" in the sh.tangled.ci.defs schema.
type CiDefs_Workflow struct {
	FinishedAt *string `json:"finishedAt,omitempty" cborgen:"finishedAt,omitempty"`
	// id: Spindle-local workflow id. Unique per pipeline, usually same as name.
	Id string `json:"id" cborgen:"id"`
	// name: Name of the workflow
	Name      string  `json:"name" cborgen:"name"`
	StartedAt *string `json:"startedAt,omitempty" cborgen:"startedAt,omitempty"`
	// status: Workflow status
	Status string `json:"status" cborgen:"status"`
}
