// CODE GENERATED BY github.com/golingon/lingon. DO NOT EDIT.

package local_file

import (
	"encoding/json"
	"fmt"
	"io"

	"github.com/golingon/lingon/pkg/terra"
)

var _ terra.Resource = (*Resource)(nil)

// Resource represents the Terraform resource local_file.
type Resource struct {
	Name      string
	Args      Args
	state     *localFileState
	DependsOn terra.Dependencies
	Lifecycle *terra.Lifecycle
}

// Type returns the Terraform object type for [Resource].
func (lf *Resource) Type() string {
	return "local_file"
}

// LocalName returns the local name for [Resource].
func (lf *Resource) LocalName() string {
	return lf.Name
}

// Configuration returns the configuration (args) for [Resource].
func (lf *Resource) Configuration() interface{} {
	return lf.Args
}

// DependOn is used for other resources to depend on [Resource].
func (lf *Resource) DependOn() terra.Reference {
	return terra.ReferenceResource(lf)
}

// Dependencies returns the list of resources [Resource] depends_on.
func (lf *Resource) Dependencies() terra.Dependencies {
	return lf.DependsOn
}

// LifecycleManagement returns the lifecycle block for [Resource].
func (lf *Resource) LifecycleManagement() *terra.Lifecycle {
	return lf.Lifecycle
}

// Attributes returns the attributes for [Resource].
func (lf *Resource) Attributes() localFileAttributes {
	return localFileAttributes{ref: terra.ReferenceResource(lf)}
}

// ImportState imports the given attribute values into [Resource]'s state.
func (lf *Resource) ImportState(state io.Reader) error {
	lf.state = &localFileState{}
	if err := json.NewDecoder(state).Decode(lf.state); err != nil {
		return fmt.Errorf("decoding state into resource %s.%s: %w", lf.Type(), lf.LocalName(), err)
	}
	return nil
}

// State returns the state and a bool indicating if [Resource] has state.
func (lf *Resource) State() (*localFileState, bool) {
	return lf.state, lf.state != nil
}

// StateMust returns the state for [Resource]. Panics if the state is nil.
func (lf *Resource) StateMust() *localFileState {
	if lf.state == nil {
		panic(fmt.Sprintf("state is nil for resource %s.%s", lf.Type(), lf.LocalName()))
	}
	return lf.state
}

// Args contains the configurations for local_file.
type Args struct {
	// Content: string, optional
	Content terra.StringValue `hcl:"content,attr"`
	// ContentBase64: string, optional
	ContentBase64 terra.StringValue `hcl:"content_base64,attr"`
	// DirectoryPermission: string, optional
	DirectoryPermission terra.StringValue `hcl:"directory_permission,attr"`
	// FilePermission: string, optional
	FilePermission terra.StringValue `hcl:"file_permission,attr"`
	// Filename: string, required
	Filename terra.StringValue `hcl:"filename,attr" validate:"required"`
	// SensitiveContent: string, optional
	SensitiveContent terra.StringValue `hcl:"sensitive_content,attr"`
	// Source: string, optional
	Source terra.StringValue `hcl:"source,attr"`
}

type localFileAttributes struct {
	ref terra.Reference
}

// Content returns a reference to field content of local_file.
func (lf localFileAttributes) Content() terra.StringValue {
	return terra.ReferenceAsString(lf.ref.Append("content"))
}

// ContentBase64 returns a reference to field content_base64 of local_file.
func (lf localFileAttributes) ContentBase64() terra.StringValue {
	return terra.ReferenceAsString(lf.ref.Append("content_base64"))
}

// ContentBase64Sha256 returns a reference to field content_base64sha256 of local_file.
func (lf localFileAttributes) ContentBase64Sha256() terra.StringValue {
	return terra.ReferenceAsString(lf.ref.Append("content_base64sha256"))
}

// ContentBase64Sha512 returns a reference to field content_base64sha512 of local_file.
func (lf localFileAttributes) ContentBase64Sha512() terra.StringValue {
	return terra.ReferenceAsString(lf.ref.Append("content_base64sha512"))
}

// ContentMd5 returns a reference to field content_md5 of local_file.
func (lf localFileAttributes) ContentMd5() terra.StringValue {
	return terra.ReferenceAsString(lf.ref.Append("content_md5"))
}

// ContentSha1 returns a reference to field content_sha1 of local_file.
func (lf localFileAttributes) ContentSha1() terra.StringValue {
	return terra.ReferenceAsString(lf.ref.Append("content_sha1"))
}

// ContentSha256 returns a reference to field content_sha256 of local_file.
func (lf localFileAttributes) ContentSha256() terra.StringValue {
	return terra.ReferenceAsString(lf.ref.Append("content_sha256"))
}

// ContentSha512 returns a reference to field content_sha512 of local_file.
func (lf localFileAttributes) ContentSha512() terra.StringValue {
	return terra.ReferenceAsString(lf.ref.Append("content_sha512"))
}

// DirectoryPermission returns a reference to field directory_permission of local_file.
func (lf localFileAttributes) DirectoryPermission() terra.StringValue {
	return terra.ReferenceAsString(lf.ref.Append("directory_permission"))
}

// FilePermission returns a reference to field file_permission of local_file.
func (lf localFileAttributes) FilePermission() terra.StringValue {
	return terra.ReferenceAsString(lf.ref.Append("file_permission"))
}

// Filename returns a reference to field filename of local_file.
func (lf localFileAttributes) Filename() terra.StringValue {
	return terra.ReferenceAsString(lf.ref.Append("filename"))
}

// Id returns a reference to field id of local_file.
func (lf localFileAttributes) Id() terra.StringValue {
	return terra.ReferenceAsString(lf.ref.Append("id"))
}

// SensitiveContent returns a reference to field sensitive_content of local_file.
func (lf localFileAttributes) SensitiveContent() terra.StringValue {
	return terra.ReferenceAsString(lf.ref.Append("sensitive_content"))
}

// Source returns a reference to field source of local_file.
func (lf localFileAttributes) Source() terra.StringValue {
	return terra.ReferenceAsString(lf.ref.Append("source"))
}

type localFileState struct {
	Content             string `json:"content"`
	ContentBase64       string `json:"content_base64"`
	ContentBase64Sha256 string `json:"content_base64sha256"`
	ContentBase64Sha512 string `json:"content_base64sha512"`
	ContentMd5          string `json:"content_md5"`
	ContentSha1         string `json:"content_sha1"`
	ContentSha256       string `json:"content_sha256"`
	ContentSha512       string `json:"content_sha512"`
	DirectoryPermission string `json:"directory_permission"`
	FilePermission      string `json:"file_permission"`
	Filename            string `json:"filename"`
	Id                  string `json:"id"`
	SensitiveContent    string `json:"sensitive_content"`
	Source              string `json:"source"`
}
