package com.mobc3.platform.backend.commons.architecture.oauth2.client;

import com.mobc3.platform.backend.commons.architecture.urlencodedform.*;

public class AccessTokenRequestWithResourceOwnerPasswordCredentialsGrant extends AccessTokenRequest  {

	public static final String SCOPE_PARAMETER = "scope";
	public static final String USERNAME_PARAMETER = "username";
	public static final String PASSWORD_PARAMETER = "password";
	
	private String userName;
	private String password;
	private String scope;
	
	public AccessTokenRequestWithResourceOwnerPasswordCredentialsGrant() {
		super(GrantTypeValue.password);
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getScope() {
		return scope;
	}

	public void setScope(String scope) {
		this.scope = scope;
	}

	@Override
	public URLEncodedForm toURLEncodedForm() {
		URLEncodedForm ret = super.toURLEncodedForm();
		if (userName != null)
			ret.setAttributeValue(USERNAME_PARAMETER, userName);
		if (password != null)
			ret.setAttributeValue(PASSWORD_PARAMETER, password);
		if (scope != null)
			ret.setAttributeValue(SCOPE_PARAMETER, scope);
		return ret;
	}

	@Override
	public void fromURLEncodedForm(URLEncodedForm form) {
		super.fromURLEncodedForm(form);
		userName = form.getAttributeValue(USERNAME_PARAMETER);
		password = form.getAttributeValue(PASSWORD_PARAMETER);
		scope = form.getAttributeValue(SCOPE_PARAMETER);
	}
	
	@Override
	public String toString() {
		return super.toString() + " [userName="	+ userName
				+ ", password="	+ password
				+ ", scope=" + scope
				+ "]";
	}

}
