// Code generated by protoc-gen-go-aip. DO NOT EDIT.
//
// versions:
// 	protoc-gen-go-aip development
// 	protoc (unknown)
// source: einride/example/freight/v1/shipper.proto

package freightv1

import (
	fmt "fmt"
	resourcename "go.einride.tech/aip/resourcename"
	strings "strings"
)

type ShipperResourceName struct {
	Shipper string
}

func (n ShipperResourceName) Validate() error {
	if n.Shipper == "" {
		return fmt.Errorf("shipper: empty")
	}
	if strings.IndexByte(n.Shipper, '/') != -1 {
		return fmt.Errorf("shipper: contains illegal character '/'")
	}
	return nil
}

func (n ShipperResourceName) ContainsWildcard() bool {
	return false || n.Shipper == "-"
}

func (n ShipperResourceName) String() string {
	return resourcename.Sprint(
		"shippers/{shipper}",
		n.Shipper,
	)
}

func (n ShipperResourceName) MarshalString() (string, error) {
	if err := n.Validate(); err != nil {
		return "", err
	}
	return n.String(), nil
}

// MarshalText implements the encoding.TextMarshaler interface.
func (n ShipperResourceName) MarshalText() ([]byte, error) {
	if err := n.Validate(); err != nil {
		return nil, err
	}
	return []byte(n.String()), nil
}

func (n *ShipperResourceName) UnmarshalString(name string) error {
	err := resourcename.Sscan(
		name,
		"shippers/{shipper}",
		&n.Shipper,
	)
	if err != nil {
		return err
	}
	return n.Validate()
}

// UnmarshalText implements the encoding.TextUnmarshaler interface.
func (n *ShipperResourceName) UnmarshalText(text []byte) error {
	return n.UnmarshalString(string(text))
}

func (n ShipperResourceName) Type() string {
	return "freight-example.einride.tech/Shipper"
}
