Module:gez-nominal


local sub = mw.ustring.sub
local com = require('Module:Ethi-common')

local export = {}

local function with_suffix(base, final_components, suffix)
    return sub(base, 1, -2) .. com.from_components(final_components) .. (suffix or '')
end

local function accusative_or_construct_form(base)
    local c = com.to_components(sub(base, -1))
    if c.order == 4 or c.order == 5 or c.order == 7 then
        return base
    elseif c.order == 2 then
        c.order = 7
    elseif c.order == 3 then
        c.order = 5
    else
        c.order = 1
    end
    return with_suffix(base, c)
end

local pronoun_suffixes = {
    ["1s"] = "የ",
    ["2ms"] = "ከ",
    ["2fs"] = "ኪ",
    ["3ms"] = "ሁ",
    ["3fs"] = "ሃ",
    ["1p"] = "ነ",
    ["2mp"] = "ክሙ",
    ["2fp"] = "ክን",
    ["3mp"] = "ሆሙ",
    ["3fp"] = "ሆን"
}

function export.external_plural(base, gender)
    local c = com.to_components(sub(base, -1))
    c.order = 4
    if gender == "m" then
        return with_suffix(base, c, "ን")
    elseif gender == "f" then
        return with_suffix(base, c, "ት")
    end
end

function export.with_pronominal_suffix(base, pronoun, base_is_plural, accusative)
    local output = {}
    local c = com.to_components(sub(base, -1))
    local suffix = pronoun_suffixes[pronoun]
    if c.order == 3 and sub(pronoun, 1, 1) == "2" and accusative then
        c.order = 5
    end
    if base_is_plural then
        if pronoun == "1s" then
            c.order = 6
        elseif pronoun == "2fs" then
            c.order = 6
            table.insert(output, with_suffix(base, c, suffix))
            c.order = 3
        else
            c.order = 3
        end
    else
        if c.order == 1 or c.order == 6 then
            if accusative and pronoun ~= "1s" then
                c.order = 1
            else
                c.order = 6
            end
            if pronoun == "3ms" then
                if accusative then
                    c.order = 7
                else
                    c.order = 2
                end
                suffix = ""
            elseif pronoun == "3fs" then
                c.order = 4
                suffix = ""
            elseif pronoun == "3mp" then
                c.order = 7
                suffix = "ሙ"
            elseif pronoun == "3fp" then
                c.order = 7
                suffix = "ን"
            end
        end
    end
    table.insert(output, with_suffix(base, c, suffix))
    return output
end

function export.construct_form(base)
    return accusative_or_construct_form(base)
end

function export.accusative_form(base, personal_name)
    return accusative_or_construct_form(base)
end

return export