--[=[
Implements [[Template:PD-EdictGov]] and related templates
]=]

local p = {} --p stands for package

local getArgs = require('Module:Arguments').getArgs
local PD = require('Module:PD')

local EdictGov_text = " in the '''[[w:public domain|public domain]] in the U.S.''' because " .. PD.license_grammar({"it is an [[wikipedia:Edict of government|edict of a government]]", "they are [[wikipedia:Edict of government|edicts of a government]]"}) .. ", local or foreign. See [https://www.copyright.gov/comp3/ § 313.6(C)(2) of the Compendium II: Copyright Office Practices]. Such documents include "legislative enactments, judicial decisions, administrative rulings, public ordinances, or similar types of official legal materials" as well as "any translation prepared by a government employee acting within the course of his or her official duties.""

function p._PD_EdictGov(args)
	local text = PD.license_scope() .. EdictGov_text .. "\n\nThese do '''not''' include works of the Organization of American States, United Nations, or any of the UN specialized agencies. See Compendium III § 313.6(C)(2) and 17 U.S.C. 104(b)(5)."
	local warning = "A non-American governmental edict may still be copyrighted outside the U.S. Similar to {{[[Template:PD-in-USGov|PD-in-USGov]]}}, the above U.S. Copyright Office Practice does not prevent U.S. states or localities from holding copyright abroad, depending on foreign copyright laws and regulations."
	return PD.license({
		['image'] = PD.PD_image,
		['image_r'] = PD.US_flag_image,
		['text'] = text,
		['warning'] = warning,
		['category'] = args.category or "PD-EdictGov"
	})
end

function p.PD_EdictGov(frame)
	return p._PD_EdictGov(getArgs(frame))
end

function p._PD_ParticularGov(args)
	local data = require('Module:PD-EdictGov/data')
	
	local template = args.template
	if not template then
		return PD.error_text("[[Module:PD-EdictGov]] error: _PD_ParticularGov requires a template to be specified.", nil)
	elseif not data[template] or not data[template]['text'] then
		return PD.error_text("[[Module:PD-EdictGov]] error: " .. template .. " is not a template supported by _PD_ParticularGov.", nil)
	end
	
	return PD.license({
		['image'] = PD.PD_image,
		['image_r'] = data[template]['image_r'],
		['text'] = data[template]['text'] .. "\n----\n" .. PD.license_scope() .. " also" .. EdictGov_text,
		['category'] = args.category or data[template]['category'] or template,
		['warning'] = data[template]['warning']
	})
end

function p.PD_ParticularGov(frame)
	return p._PD_ParticularGov(getArgs(frame))
end

return p