// Copyright © 2023 Cisco Systems, Inc. and its affiliates.
// All rights reserved.
//
// Licensed under the Mozilla Public License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     https://mozilla.org/MPL/2.0/
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// SPDX-License-Identifier: MPL-2.0

// Code generated by "gen/generator.go"; DO NOT EDIT.

package provider

// Section below is generated&owned by "gen/generator.go". //template:begin imports
import (
	"context"
	"fmt"

	"github.com/hashicorp/terraform-plugin-framework/datasource"
	"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
	"github.com/hashicorp/terraform-plugin-framework/path"
	"github.com/hashicorp/terraform-plugin-framework/types"
	"github.com/hashicorp/terraform-plugin-log/tflog"
)

// End of section. //template:end imports

// Section below is generated&owned by "gen/generator.go". //template:begin model

// Ensure the implementation satisfies the expected interfaces.
var (
	_ datasource.DataSource              = &AAAAccountingDataSource{}
	_ datasource.DataSourceWithConfigure = &AAAAccountingDataSource{}
)

func NewAAAAccountingDataSource() datasource.DataSource {
	return &AAAAccountingDataSource{}
}

type AAAAccountingDataSource struct {
	data *IosxeProviderData
}

func (d *AAAAccountingDataSource) Metadata(_ context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
	resp.TypeName = req.ProviderTypeName + "_aaa_accounting"
}

func (d *AAAAccountingDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
	resp.Schema = schema.Schema{
		// This description is used by the documentation generator and the language server.
		MarkdownDescription: "This data source can read the AAA Accounting configuration.",

		Attributes: map[string]schema.Attribute{
			"device": schema.StringAttribute{
				MarkdownDescription: "A device name from the provider configuration.",
				Optional:            true,
			},
			"id": schema.StringAttribute{
				MarkdownDescription: "The path of the retrieved object.",
				Computed:            true,
			},
			"update_newinfo_periodic": schema.Int64Attribute{
				MarkdownDescription: "Periodic intervals to send accounting update records(in minutes)",
				Computed:            true,
			},
			"identities": schema.ListNestedAttribute{
				MarkdownDescription: "Named Accounting list (max 31 characters, longer will be rejected).",
				Computed:            true,
				NestedObject: schema.NestedAttributeObject{
					Attributes: map[string]schema.Attribute{
						"name": schema.StringAttribute{
							MarkdownDescription: "",
							Computed:            true,
						},
						"start_stop_broadcast": schema.BoolAttribute{
							MarkdownDescription: "Use Broadcast for Accounting",
							Computed:            true,
						},
						"start_stop_group_broadcast": schema.BoolAttribute{
							MarkdownDescription: "Use Broadcast for Accounting",
							Computed:            true,
						},
						"start_stop_group_logger": schema.BoolAttribute{
							MarkdownDescription: "Use system logger for Accounting",
							Computed:            true,
						},
						"start_stop_group1": schema.StringAttribute{
							MarkdownDescription: "Use Server-group",
							Computed:            true,
						},
						"start_stop_group2": schema.StringAttribute{
							MarkdownDescription: "Use Server-group",
							Computed:            true,
						},
						"start_stop_group3": schema.StringAttribute{
							MarkdownDescription: "Use Server-group",
							Computed:            true,
						},
						"start_stop_group4": schema.StringAttribute{
							MarkdownDescription: "Use Server-group",
							Computed:            true,
						},
					},
				},
			},
			"identity_default_start_stop_group1": schema.StringAttribute{
				MarkdownDescription: "Use Server-group",
				Computed:            true,
			},
			"identity_default_start_stop_group2": schema.StringAttribute{
				MarkdownDescription: "Use Server-group",
				Computed:            true,
			},
			"identity_default_start_stop_group3": schema.StringAttribute{
				MarkdownDescription: "Use Server-group",
				Computed:            true,
			},
			"identity_default_start_stop_group4": schema.StringAttribute{
				MarkdownDescription: "Use Server-group",
				Computed:            true,
			},
			"networks": schema.ListNestedAttribute{
				MarkdownDescription: "For network services. (PPP, SLIP, ARAP)",
				Computed:            true,
				NestedObject: schema.NestedAttributeObject{
					Attributes: map[string]schema.Attribute{
						"id": schema.StringAttribute{
							MarkdownDescription: "",
							Computed:            true,
						},
						"start_stop_group1": schema.StringAttribute{
							MarkdownDescription: "Use Server-group",
							Computed:            true,
						},
						"start_stop_group2": schema.StringAttribute{
							MarkdownDescription: "Use Server-group",
							Computed:            true,
						},
					},
				},
			},
			"system_guarantee_first": schema.BoolAttribute{
				MarkdownDescription: "Guarantee system accounting as first record.",
				Computed:            true,
			},
			"commands": schema.ListNestedAttribute{
				MarkdownDescription: "For exec (shell) commands.",
				Computed:            true,
				NestedObject: schema.NestedAttributeObject{
					Attributes: map[string]schema.Attribute{
						"level": schema.Int64Attribute{
							MarkdownDescription: "Enable level",
							Computed:            true,
						},
						"list_name": schema.StringAttribute{
							MarkdownDescription: "",
							Computed:            true,
						},
						"action_type": schema.StringAttribute{
							MarkdownDescription: "",
							Computed:            true,
						},
						"broadcast": schema.BoolAttribute{
							MarkdownDescription: "Use Broadcast for Accounting",
							Computed:            true,
						},
						"group_broadcast": schema.BoolAttribute{
							MarkdownDescription: "Use Broadcast for Accounting",
							Computed:            true,
						},
						"group_logger": schema.BoolAttribute{
							MarkdownDescription: "Use system logger for Accounting",
							Computed:            true,
						},
						"group1_group": schema.StringAttribute{
							MarkdownDescription: "Use Server-group",
							Computed:            true,
						},
						"group2_group": schema.StringAttribute{
							MarkdownDescription: "Use Server-group",
							Computed:            true,
						},
						"group3_group": schema.StringAttribute{
							MarkdownDescription: "Use Server-group",
							Computed:            true,
						},
						"group4_group": schema.StringAttribute{
							MarkdownDescription: "Use Server-group",
							Computed:            true,
						},
					},
				},
			},
			"connections": schema.ListNestedAttribute{
				MarkdownDescription: "For outbound connections. (telnet, rlogin)",
				Computed:            true,
				NestedObject: schema.NestedAttributeObject{
					Attributes: map[string]schema.Attribute{
						"name": schema.StringAttribute{
							MarkdownDescription: "",
							Computed:            true,
						},
						"default": schema.BoolAttribute{
							MarkdownDescription: "",
							Computed:            true,
						},
						"none": schema.BoolAttribute{
							MarkdownDescription: "No accounting.",
							Computed:            true,
						},
						"start_stop_broadcast": schema.BoolAttribute{
							MarkdownDescription: "Use Broadcast for Accounting",
							Computed:            true,
						},
						"start_stop_logger": schema.BoolAttribute{
							MarkdownDescription: "Use system logger for Accounting",
							Computed:            true,
						},
						"start_stop_group1": schema.StringAttribute{
							MarkdownDescription: "Use Server-group",
							Computed:            true,
						},
						"start_stop_group2": schema.StringAttribute{
							MarkdownDescription: "Use Server-group",
							Computed:            true,
						},
						"start_stop_group3": schema.StringAttribute{
							MarkdownDescription: "Use Server-group",
							Computed:            true,
						},
						"start_stop_group4": schema.StringAttribute{
							MarkdownDescription: "Use Server-group",
							Computed:            true,
						},
						"stop_only_broadcast": schema.BoolAttribute{
							MarkdownDescription: "Use Broadcast for Accounting",
							Computed:            true,
						},
						"stop_only_logger": schema.BoolAttribute{
							MarkdownDescription: "Use system logger for Accounting",
							Computed:            true,
						},
						"stop_only_group1": schema.StringAttribute{
							MarkdownDescription: "Use Server-group",
							Computed:            true,
						},
						"stop_only_group2": schema.StringAttribute{
							MarkdownDescription: "Use Server-group",
							Computed:            true,
						},
						"stop_only_group3": schema.StringAttribute{
							MarkdownDescription: "Use Server-group",
							Computed:            true,
						},
						"stop_only_group4": schema.StringAttribute{
							MarkdownDescription: "Use Server-group",
							Computed:            true,
						},
						"wait_start_broadcast": schema.BoolAttribute{
							MarkdownDescription: "Use Broadcast for Accounting",
							Computed:            true,
						},
						"wait_start_logger": schema.BoolAttribute{
							MarkdownDescription: "Use system logger for Accounting",
							Computed:            true,
						},
						"wait_start_group1": schema.StringAttribute{
							MarkdownDescription: "Use Server-group",
							Computed:            true,
						},
						"wait_start_group2": schema.StringAttribute{
							MarkdownDescription: "Use Server-group",
							Computed:            true,
						},
						"wait_start_group3": schema.StringAttribute{
							MarkdownDescription: "Use Server-group",
							Computed:            true,
						},
						"wait_start_group4": schema.StringAttribute{
							MarkdownDescription: "Use Server-group",
							Computed:            true,
						},
					},
				},
			},
			"execs": schema.ListNestedAttribute{
				MarkdownDescription: "For starting an exec (shell).",
				Computed:            true,
				NestedObject: schema.NestedAttributeObject{
					Attributes: map[string]schema.Attribute{
						"name": schema.StringAttribute{
							MarkdownDescription: "",
							Computed:            true,
						},
						"none": schema.BoolAttribute{
							MarkdownDescription: "No accounting.",
							Computed:            true,
						},
						"start_stop_broadcast": schema.BoolAttribute{
							MarkdownDescription: "Use Broadcast for Accounting",
							Computed:            true,
						},
						"start_stop_logger": schema.BoolAttribute{
							MarkdownDescription: "Use system logger for Accounting",
							Computed:            true,
						},
						"start_stop_group1": schema.StringAttribute{
							MarkdownDescription: "Use Server-group",
							Computed:            true,
						},
						"start_stop_group2": schema.StringAttribute{
							MarkdownDescription: "Use Server-group",
							Computed:            true,
						},
						"start_stop_group3": schema.StringAttribute{
							MarkdownDescription: "Use Server-group",
							Computed:            true,
						},
						"start_stop_group4": schema.StringAttribute{
							MarkdownDescription: "Use Server-group",
							Computed:            true,
						},
						"stop_only_broadcast": schema.BoolAttribute{
							MarkdownDescription: "Use Broadcast for Accounting",
							Computed:            true,
						},
						"stop_only_logger": schema.BoolAttribute{
							MarkdownDescription: "Use system logger for Accounting",
							Computed:            true,
						},
						"stop_only_group1": schema.StringAttribute{
							MarkdownDescription: "Use Server-group",
							Computed:            true,
						},
						"stop_only_group2": schema.StringAttribute{
							MarkdownDescription: "Use Server-group",
							Computed:            true,
						},
						"stop_only_group3": schema.StringAttribute{
							MarkdownDescription: "Use Server-group",
							Computed:            true,
						},
						"stop_only_group4": schema.StringAttribute{
							MarkdownDescription: "Use Server-group",
							Computed:            true,
						},
						"wait_start_broadcast": schema.BoolAttribute{
							MarkdownDescription: "Use Broadcast for Accounting",
							Computed:            true,
						},
						"wait_start_logger": schema.BoolAttribute{
							MarkdownDescription: "Use system logger for Accounting",
							Computed:            true,
						},
						"wait_start_group1": schema.StringAttribute{
							MarkdownDescription: "Use Server-group",
							Computed:            true,
						},
						"wait_start_group2": schema.StringAttribute{
							MarkdownDescription: "Use Server-group",
							Computed:            true,
						},
						"wait_start_group3": schema.StringAttribute{
							MarkdownDescription: "Use Server-group",
							Computed:            true,
						},
						"wait_start_group4": schema.StringAttribute{
							MarkdownDescription: "Use Server-group",
							Computed:            true,
						},
					},
				},
			},
		},
	}
}

func (d *AAAAccountingDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, _ *datasource.ConfigureResponse) {
	if req.ProviderData == nil {
		return
	}

	d.data = req.ProviderData.(*IosxeProviderData)
}

// End of section. //template:end model

// Section below is generated&owned by "gen/generator.go". //template:begin read

func (d *AAAAccountingDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
	var config AAAAccountingData

	// Read config
	diags := req.Config.Get(ctx, &config)
	resp.Diagnostics.Append(diags...)
	if resp.Diagnostics.HasError() {
		return
	}

	tflog.Debug(ctx, fmt.Sprintf("%s: Beginning Read", config.getPath()))

	device, ok := d.data.Devices[config.Device.ValueString()]
	if !ok {
		resp.Diagnostics.AddAttributeError(path.Root("device"), "Invalid device", fmt.Sprintf("Device '%s' does not exist in provider configuration.", config.Device.ValueString()))
		return
	}

	res, err := device.Client.GetData(config.getPath())
	if res.StatusCode == 404 {
		config = AAAAccountingData{Device: config.Device}
	} else {
		if err != nil {
			resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Failed to retrieve object (%s), got error: %s", config.getPath(), err))
			return
		}

		config.fromBody(ctx, res.Res)
	}

	config.Id = types.StringValue(config.getPath())

	tflog.Debug(ctx, fmt.Sprintf("%s: Read finished successfully", config.getPath()))

	diags = resp.State.Set(ctx, &config)
	resp.Diagnostics.Append(diags...)
}

// End of section. //template:end read
