// Code generated by go-swagger; DO NOT EDIT.

package models

// This file was generated by the swagger tool.
// Editing this file might prove futile when you re-run the swagger generate command

import (
	"context"
	"encoding/json"

	"github.com/go-openapi/errors"
	"github.com/go-openapi/strfmt"
	"github.com/go-openapi/swag"
	"github.com/go-openapi/validate"
)

// ChangeFileOperation ChangeFileOperation for creating, updating or deleting a file
//
// swagger:model ChangeFileOperation
type ChangeFileOperation struct {

	// new or updated file content, must be base64 encoded
	ContentBase64 string `json:"content,omitempty"`

	// old path of the file to move
	FromPath string `json:"from_path,omitempty"`

	// indicates what to do with the file
	// Required: true
	// Enum: ["create","update","delete"]
	Operation *string `json:"operation"`

	// path to the existing or new file
	// Required: true
	Path *string `json:"path"`

	// sha is the SHA for the file that already exists, required for update or delete
	SHA string `json:"sha,omitempty"`
}

// Validate validates this change file operation
func (m *ChangeFileOperation) Validate(formats strfmt.Registry) error {
	var res []error

	if err := m.validateOperation(formats); err != nil {
		res = append(res, err)
	}

	if err := m.validatePath(formats); err != nil {
		res = append(res, err)
	}

	if len(res) > 0 {
		return errors.CompositeValidationError(res...)
	}
	return nil
}

var changeFileOperationTypeOperationPropEnum []interface{}

func init() {
	var res []string
	if err := json.Unmarshal([]byte(`["create","update","delete"]`), &res); err != nil {
		panic(err)
	}
	for _, v := range res {
		changeFileOperationTypeOperationPropEnum = append(changeFileOperationTypeOperationPropEnum, v)
	}
}

const (

	// ChangeFileOperationOperationCreate captures enum value "create"
	ChangeFileOperationOperationCreate string = "create"

	// ChangeFileOperationOperationUpdate captures enum value "update"
	ChangeFileOperationOperationUpdate string = "update"

	// ChangeFileOperationOperationDelete captures enum value "delete"
	ChangeFileOperationOperationDelete string = "delete"
)

// prop value enum
func (m *ChangeFileOperation) validateOperationEnum(path, location string, value string) error {
	if err := validate.EnumCase(path, location, value, changeFileOperationTypeOperationPropEnum, true); err != nil {
		return err
	}
	return nil
}

func (m *ChangeFileOperation) validateOperation(formats strfmt.Registry) error {

	if err := validate.Required("operation", "body", m.Operation); err != nil {
		return err
	}

	// value enum
	if err := m.validateOperationEnum("operation", "body", *m.Operation); err != nil {
		return err
	}

	return nil
}

func (m *ChangeFileOperation) validatePath(formats strfmt.Registry) error {

	if err := validate.Required("path", "body", m.Path); err != nil {
		return err
	}

	return nil
}

// ContextValidate validates this change file operation based on context it is used
func (m *ChangeFileOperation) ContextValidate(ctx context.Context, formats strfmt.Registry) error {
	return nil
}

// MarshalBinary interface implementation
func (m *ChangeFileOperation) MarshalBinary() ([]byte, error) {
	if m == nil {
		return nil, nil
	}
	return swag.WriteJSON(m)
}

// UnmarshalBinary interface implementation
func (m *ChangeFileOperation) UnmarshalBinary(b []byte) error {
	var res ChangeFileOperation
	if err := swag.ReadJSON(b, &res); err != nil {
		return err
	}
	*m = res
	return nil
}
